package wh.FishingPhilosopher;

import java.util.HashMap;

import wh.FishingPhilosopher.GameParams.GameParams;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;

import android.media.SoundPool;

public class FishingPhilosopherGameSound {
	private AudioManager am;
	private HashMap<Integer, Integer> soundPoolMap;
	public static int cannonSoundId;
	public static int fishCaughtSoundId;
	public static int netOpenSoundId;
	public static int cannonSwitchSoundId;
	public static SoundPool soundPool;
	public static MediaPlayer gameMediaPlayer;
	public static MediaPlayer startMediaPlayer;
	
	public void initializeSoundPool(Context context){
		am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
		am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		
		soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100);
		soundPoolMap = new HashMap<Integer, Integer>();
		
		soundPoolMap.put(1, soundPool.load(context, R.raw.sound_cannon, 1));
		cannonSoundId = soundPool.load(context, R.raw.sound_cannon, 1);
		
		soundPoolMap.put(2, soundPool.load(context, R.raw.sound_fishcaught, 1));
		fishCaughtSoundId = soundPool.load(context, R.raw.sound_fishcaught, 1);
		
		soundPoolMap.put(3, soundPool.load(context, R.raw.sound_netopen, 1));
		netOpenSoundId = soundPool.load(context, R.raw.sound_netopen, 1);
		
		soundPoolMap.put(4, soundPool.load(context, R.raw.sound_cannonswitch, 1));
		cannonSwitchSoundId = soundPool.load(context, R.raw.sound_cannonswitch, 1);	
	}
	
	public void playSound(int loadId){
		if(GameParams.isSoundOn)
			soundPool.play(loadId, 0.9f, 0.9f, 1, 0, 1f);
	}
	
	public void playGameBackgroundMusic(Context context){
		if(GameParams.isMusicOn)
		{
			gameMediaPlayer =MediaPlayer.create(context, R.raw.music_game_scene);
			gameMediaPlayer.setLooping(true);
			gameMediaPlayer.start();
		}
	}
	
	public void playStartBackgroundMusic(Context context){
		if(GameParams.isMusicOn)
		{
			startMediaPlayer =MediaPlayer.create(context, R.raw.music_start);
			startMediaPlayer.setLooping(true);
			startMediaPlayer.start();
		}
	}
	
}
